import React from 'react';
import { connect } from 'dva';

import { Modal, Form, Input } from 'antd';

const FormItem = Form.Item;

@connect(({ partnerOrgModel }) => ({ partnerOrgModel }))
class FormCreate extends React.Component {

  handleCancel(){
    const { dispatch } = this.props;
    dispatch({
      type: 'partnerOrgModel/hide',
      payload: 'newForm'
    });
  }

  handleOk(){
    const { form: { validateFields } } = this.props;
    const { dispatch } = this.props;
    validateFields( async  (err, values) => {
      if (!err) {
        const vals = {...values }
        vals.is_company = true

        await dispatch({
          type: 'partnerOrgModel/create',
          payload : { vals},
        });

        dispatch({
          type: 'partnerOrgModel/hide',
          payload: 'newForm'
        });

      }
    });
  }


  render() {
    const { partnerOrgModel:{ visible }, form: { getFieldDecorator }  } = this.props;

    return (
      <div>
        <Modal title='新增'
          visible={visible.newForm}
          onOk={()=>this.handleOk()}
          onCancel={()=>this.handleCancel()}
        >
          <Form>
            <FormItem label="name">
              {getFieldDecorator('name', {
                /*  rules: [{ required: true }], */
                initialValue: 'n',
              })(
                <Input />
              )}
            </FormItem>

          </Form>
        </Modal>

      </div>
    );
  }


}

export default Form.create()(FormCreate);

